<template>
  <div class="newsinfo-container">
    <h3 class="title">{{ newsInfo.title }}</h3>
    <p class="info">
      <span>发表时间: {{ newsInfo.add_time | dateFormat }}</span>
      <span>点击: {{ newsInfo.click }}次</span>
    </p>
    <hr />
    <div class="content" v-html="newsInfo.content"></div>

    <!-- 向子子组件传入新闻id -->
    <comment :newsid="id"></comment>
  </div>
</template>

<script>
// 二、导入评论子组件
import comment from "../sub-components/Comment"

export default {
  created() {
    // console.log(this)
    // console.log(this.$route.params.id)
    // 跳转到新闻详情页时调用获取详情信息到方法
    this.getNewsInfo()
  },
  data() {
    return {
      // 新闻详情
      newsInfo: {},
    }
  },
  props: ["id"],
  methods: {
    // 一、获取详情信息到方法
    async getNewsInfo() {
      // 1.1 发送请求
      const { data } = await this.$http.get(`/api/getnew/${this.id}`)
      // 1.2 获取数据
      if (data.status === 0) return (this.newsInfo = data.message[0])
    },
  },
  // 三、注册子组件
  components: { comment },
}
</script>

<style lang="scss" scoped>
.newsinfo-container {
  padding: 5px;
  .title {
    font-size: 15px;
    text-align: center;
    color: red;
    margin: 15px 0;
  }
  .info {
    display: flex;
    justify-content: space-between;
    color: #26a2ff;
  }
}
</style>
